package cc.togetherit.jcrawler.parse;

import java.util.HashMap;
import java.util.Map;

import org.jsoup.Jsoup;

import cc.togetherit.jcrawler.dataPool.CrawlerPool;
import cc.togetherit.jcrawler.fetch.FetchRequest;
import cc.togetherit.jcrawler.parser.SiteParser;
import cc.togetherit.jcrawler.util.HtmlCleanerUtil;

/***
 * 
 * @author jackie
 *
 */
public/***abstract***/class BaseParseEngine extends AbstractParseEngine {

    private SiteParser parser;

    public BaseParseEngine(CrawlerPool<FetchRequest> parsePool, CrawlerPool<Map<String, Object>> persistencePool, ParseConfig parseConfig, SiteParser parser) {
        super(parsePool, persistencePool, parseConfig, true);
        this.parser = parser;
    }



    @Override
    public Map<String, Object> parse(String content) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.putAll(parser.parseDetail(Jsoup.parse(content)));
        map.putAll(parser.parseDetail(HtmlCleanerUtil.getInstance().getHtmlTag(content)));
        return map;
    }

    @Override
    public boolean persistence(Map<String, Object> metaInfo) {

        return parser.save(metaInfo);

    }



    public SiteParser getParser() {
        return parser;
    }



    public void setParser(SiteParser parser) {
        this.parser = parser;
    }



   

}
